package com.gitee.wsl.compose.ui.richtext.edit.model.span.style

import androidx.compose.ui.text.SpanStyle
import com.gitee.wsl.compose.ui.richtext.edit.annotation.ExperimentalRichTextApi
import com.gitee.wsl.compose.ui.richtext.edit.model.RichTextConfig

@OptIn(ExperimentalRichTextApi::class)
class Link(
    val url: String,
) : RichSpanStyle {

    override val spanStyle: (RichTextConfig) -> SpanStyle = {
        SpanStyle(
            color = it.linkColor,
            textDecoration = it.linkTextDecoration,
        )
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Link) return false

        if (url != other.url) return false

        return true
    }

    override fun hashCode(): Int {
        return url.hashCode()
    }
}

@OptIn(ExperimentalRichTextApi::class)
fun RichSpanStyle.link(url: String) = Link(url)